export default function () {
    _.assign(Creep.prototype, creepExtension)
}

const creepExtension = {
    work: function () {
        if (!this.memory.hasSendRebirth) {
            const health = this.isHealthy()
            if (!health) {
                // 向指定 spawn 推送生成任务
                // ...
                this.memory.hasSendRebirth = true
            }
        }
    },
    isHealthy: function () {
        return this.ticksToLive > 20;
    },
    /**
     * 生命自检如果小于40，则自动跑到母巢
     */
    creepSelfCheck: function (creep) {
        const spawn = creep.room.find(FIND_STRUCTURES, {
            filter: (structure) => {
                return structure.structureType === STRUCTURE_SPAWN
            }
        })
        if (!creep.isHealthy) {
            creep.moveTo(spawn[0])
        }
    }
}